<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>WindowsScript | lilei</title>
    <meta name="generator" content="VuePress 1.8.2">
    <link rel="icon" href="/images/icons/logo.png">
    <link rel="apple-touch-icon" href="/images/icons/logo.png">
    <link rel="manifest" href="/manifest.json">
    <script type="text/javascript" src="/assets/js/load.js"></script>
    <meta name="description" content="个人网站">
    <meta name="twitter:title" content="WindowsScript">
    <meta name="twitter:description" content="">
    <meta name="twitter:card" content="summary">
    <meta name="twitter:url" content="http://www.lileiblog.xyz/Shell/WindowsScript.html">
    <meta property="og:type" content="article">
    <meta property="og:title" content="WindowsScript">
    <meta property="og:description" content="">
    <meta property="og:url" content="http://www.lileiblog.xyz/Shell/WindowsScript.html">
    <meta property="og:site_name" content="lilei">
    <meta itemprop="name" content="WindowsScript">
    <meta itemprop="description" content="">
    <meta name="theme-color" content="#3eaf7c">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="msapplication-TileImage" content="/images/icons/logo.png">
    <meta name="msapplication-TileColor" content="#ffffff">
    <meta name="keywords" content="lilei,vue,vuepress,vuepress-theme,theme,主题,vuepress主题,blog
        ,vuepress-blog,java,python,shell,sql,golang,script,shell script,nginx,windows,去广告,androd,google drive
        ,one drive,idea,eclipse,git,小程序">
    <meta name="referrer" content="never">
    
    <link rel="preload" href="/assets/css/0.styles.8932179b.css" as="style"><link rel="preload" href="/assets/js/app.269009d6.js" as="script"><link rel="preload" href="/assets/js/3.974b9720.js" as="script"><link rel="preload" href="/assets/js/63.a9516572.js" as="script"><link rel="prefetch" href="/assets/js/10.5915e99b.js"><link rel="prefetch" href="/assets/js/11.ff732762.js"><link rel="prefetch" href="/assets/js/12.8bb86d91.js"><link rel="prefetch" href="/assets/js/13.18bde5b0.js"><link rel="prefetch" href="/assets/js/14.314fae34.js"><link rel="prefetch" href="/assets/js/15.0a4ff48f.js"><link rel="prefetch" href="/assets/js/16.ffaf1503.js"><link rel="prefetch" href="/assets/js/17.49a31a6e.js"><link rel="prefetch" href="/assets/js/18.7e6443bf.js"><link rel="prefetch" href="/assets/js/19.6880cc9a.js"><link rel="prefetch" href="/assets/js/20.1fb3f255.js"><link rel="prefetch" href="/assets/js/21.0cd39eea.js"><link rel="prefetch" href="/assets/js/22.392d85cb.js"><link rel="prefetch" href="/assets/js/23.f50adb15.js"><link rel="prefetch" href="/assets/js/24.43e324e1.js"><link rel="prefetch" href="/assets/js/25.e3663205.js"><link rel="prefetch" href="/assets/js/26.da141fb8.js"><link rel="prefetch" href="/assets/js/27.6c05235a.js"><link rel="prefetch" href="/assets/js/28.c124245a.js"><link rel="prefetch" href="/assets/js/29.d185870d.js"><link rel="prefetch" href="/assets/js/30.8587d422.js"><link rel="prefetch" href="/assets/js/31.dc382b56.js"><link rel="prefetch" href="/assets/js/32.20ba32e9.js"><link rel="prefetch" href="/assets/js/33.6ecd7de9.js"><link rel="prefetch" href="/assets/js/34.2b91c13a.js"><link rel="prefetch" href="/assets/js/35.66ed0733.js"><link rel="prefetch" href="/assets/js/36.ce7bca84.js"><link rel="prefetch" href="/assets/js/37.d00bb5ac.js"><link rel="prefetch" href="/assets/js/38.c3ecbb6f.js"><link rel="prefetch" href="/assets/js/39.308f4175.js"><link rel="prefetch" href="/assets/js/4.520f6ecc.js"><link rel="prefetch" href="/assets/js/40.f4b98bc2.js"><link rel="prefetch" href="/assets/js/41.95fae64f.js"><link rel="prefetch" href="/assets/js/42.fe4f877b.js"><link rel="prefetch" href="/assets/js/43.ca8f222e.js"><link rel="prefetch" href="/assets/js/44.4d4ee79e.js"><link rel="prefetch" href="/assets/js/45.79178b33.js"><link rel="prefetch" href="/assets/js/46.c3817d0b.js"><link rel="prefetch" href="/assets/js/47.b8252443.js"><link rel="prefetch" href="/assets/js/48.df9d5d3b.js"><link rel="prefetch" href="/assets/js/49.d812fdb2.js"><link rel="prefetch" href="/assets/js/5.f1a24a16.js"><link rel="prefetch" href="/assets/js/50.55cfcaa8.js"><link rel="prefetch" href="/assets/js/51.b8608b02.js"><link rel="prefetch" href="/assets/js/52.52c5e00d.js"><link rel="prefetch" href="/assets/js/53.3a9bd5fb.js"><link rel="prefetch" href="/assets/js/54.a4240c13.js"><link rel="prefetch" href="/assets/js/55.01c4b876.js"><link rel="prefetch" href="/assets/js/56.f29549a3.js"><link rel="prefetch" href="/assets/js/57.01438a04.js"><link rel="prefetch" href="/assets/js/58.29bb4626.js"><link rel="prefetch" href="/assets/js/59.e8b89408.js"><link rel="prefetch" href="/assets/js/6.8c478b39.js"><link rel="prefetch" href="/assets/js/60.bedb5381.js"><link rel="prefetch" href="/assets/js/61.bdfbe584.js"><link rel="prefetch" href="/assets/js/62.cb825d1a.js"><link rel="prefetch" href="/assets/js/64.aa854ed7.js"><link rel="prefetch" href="/assets/js/65.285f883d.js"><link rel="prefetch" href="/assets/js/66.12849f37.js"><link rel="prefetch" href="/assets/js/67.c18b00e4.js"><link rel="prefetch" href="/assets/js/68.fa59daa9.js"><link rel="prefetch" href="/assets/js/69.e9d5dda4.js"><link rel="prefetch" href="/assets/js/7.cfb0d0ea.js"><link rel="prefetch" href="/assets/js/70.db126cce.js"><link rel="prefetch" href="/assets/js/71.6acb04cd.js"><link rel="prefetch" href="/assets/js/72.7ff0ab11.js"><link rel="prefetch" href="/assets/js/73.9a66da79.js"><link rel="prefetch" href="/assets/js/74.0a38a030.js"><link rel="prefetch" href="/assets/js/75.7b32dbb3.js"><link rel="prefetch" href="/assets/js/8.cb9c08e5.js"><link rel="prefetch" href="/assets/js/9.ad652cfe.js"><link rel="prefetch" href="/assets/js/vendors~flowchart.110a1065.js">
    <link rel="stylesheet" href="/assets/css/0.styles.8932179b.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/images/icons/logo.png" alt="lilei" class="logo"> <span class="site-name can-hide">lilei</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/Form/" class="nav-link">
  Form
</a></div><div class="nav-item"><a href="/IDE/" class="nav-link">
  IDE
</a></div><div class="nav-item"><a href="/Java/" class="nav-link">
  Java
</a></div><div class="nav-item"><a href="/Other/" class="nav-link">
  Other
</a></div><div class="nav-item"><a href="/Python/" class="nav-link">
  Python
</a></div><div class="nav-item"><a href="/SQL/" class="nav-link">
  SQL
</a></div><div class="nav-item"><a href="/Shell/" class="nav-link router-link-active">
  Shell
</a></div><div class="nav-item"><a href="/System/" class="nav-link">
  System
</a></div> <a href="https://github.com/woytu/notes-vuepress" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/Form/" class="nav-link">
  Form
</a></div><div class="nav-item"><a href="/IDE/" class="nav-link">
  IDE
</a></div><div class="nav-item"><a href="/Java/" class="nav-link">
  Java
</a></div><div class="nav-item"><a href="/Other/" class="nav-link">
  Other
</a></div><div class="nav-item"><a href="/Python/" class="nav-link">
  Python
</a></div><div class="nav-item"><a href="/SQL/" class="nav-link">
  SQL
</a></div><div class="nav-item"><a href="/Shell/" class="nav-link router-link-active">
  Shell
</a></div><div class="nav-item"><a href="/System/" class="nav-link">
  System
</a></div> <a href="https://github.com/woytu/notes-vuepress" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>Shell</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/Shell/" aria-current="page" class="sidebar-link">Shell</a></li><li><a href="/Shell/PowerShell.html" class="sidebar-link">PowerShell</a></li><li><a href="/Shell/ShellScript.html" class="sidebar-link">ShellScript</a></li><li><a href="/Shell/ShellWindows.html" class="sidebar-link">ShellWindows</a></li><li><a href="/Shell/Shell命令.html" class="sidebar-link">Shell命令</a></li><li><a href="/Shell/WindowsBatch.html" class="sidebar-link">WindowsBatch</a></li><li><a href="/Shell/WindowsJScript.html" class="sidebar-link">WindowsJScript</a></li><li><a href="/Shell/WindowsScript.html" aria-current="page" class="active sidebar-link">WindowsScript</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/Shell/WindowsScript.html#flag" class="sidebar-link">Flag</a></li><li class="sidebar-sub-header"><a href="/Shell/WindowsScript.html#wscript对象" class="sidebar-link">WScript对象</a></li><li class="sidebar-sub-header"><a href="/Shell/WindowsScript.html#常用组件对象" class="sidebar-link">常用组件对象</a></li><li class="sidebar-sub-header"><a href="/Shell/WindowsScript.html#http" class="sidebar-link">HTTP</a></li><li class="sidebar-sub-header"><a href="/Shell/WindowsScript.html#图像处理" class="sidebar-link">图像处理</a></li><li class="sidebar-sub-header"><a href="/Shell/WindowsScript.html#操作文件" class="sidebar-link">操作文件</a></li><li class="sidebar-sub-header"><a href="/Shell/WindowsScript.html#shell" class="sidebar-link">Shell</a></li><li class="sidebar-sub-header"><a href="/Shell/WindowsScript.html#wmi和mi" class="sidebar-link">WMI和MI</a></li></ul></li><li><a href="/Shell/WindowsVBScript.html" class="sidebar-link">WindowsVBScript</a></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="windowsscript"><a href="#windowsscript" class="header-anchor">#</a> WindowsScript</h1> <p></p><div class="table-of-contents"><ul><li><a href="#flag">Flag</a></li><li><a href="#wscript对象">WScript对象</a><ul><li><a href="#wscript对象的属性">WScript对象的属性</a></li><li><a href="#wscript对象的方法">WScript对象的方法</a></li></ul></li><li><a href="#常用组件对象">常用组件对象</a></li><li><a href="#http">HTTP</a></li><li><a href="#图像处理">图像处理</a></li><li><a href="#操作文件">操作文件</a></li><li><a href="#shell">Shell</a><ul><li><a href="#执行命令">执行命令</a></li><li><a href="#特殊文件夹">特殊文件夹</a></li><li><a href="#模拟按键">模拟按键</a></li></ul></li><li><a href="#wmi和mi">WMI和MI</a></li></ul></div><p></p> <h2 id="flag"><a href="#flag" class="header-anchor">#</a> Flag</h2> <ul><li><a href="https://docs.microsoft.com/zh-cn/previous-versions/ms950396(v=msdn.10)" target="_blank" rel="noopener noreferrer">Scripting<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://docs.microsoft.com/zh-cn/previous-versions/windows/internet-explorer/ie-developer/windows-scripting/bstcxhf7(v=vs.84)#in-this-section" target="_blank" rel="noopener noreferrer">Windows脚本和Windows Script Host的属性和方法及子对象<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/mrpapercut/wscript" target="_blank" rel="noopener noreferrer">https://github.com/mrpapercut/wscript<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <ul><li><a href="https://docs.microsoft.com/zh-cn/office/vba/api/overview/language-reference" target="_blank" rel="noopener noreferrer">Visual Basic for Applications (VBA) 语言参考<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li>Microsoft Office Development <a href="https://bettersolutions.com" target="_blank" rel="noopener noreferrer">https://bettersolutions.com<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://www.zhihu.com/people/xia-xi-lan/posts" target="_blank" rel="noopener noreferrer">VBA学习笔记<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://blog.csdn.net/wordsin/article/details/80575615" target="_blank" rel="noopener noreferrer">xcel之VBA简单宏编程<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li>批处理之家 <a href="http://www.bathome.net" target="_blank" rel="noopener noreferrer">http://www.bathome.net<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li>中国DOS联盟 <a href="http://cndos.fam.cx/forum/forumdisplay.php?fid=23" target="_blank" rel="noopener noreferrer">DOS批处理 &amp; 脚本技术（批处理室）<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <ul><li><code>JScript</code>、<code>VBScript</code>同属于官方支持的<code>Windows Script</code>，这俩脚本都需要依赖于特定的宿主(<code>Host</code>)才能执行，
<code>JavaScript</code>浏览器环境之外，还可以运行在<code>Windows Script Host</code>中。</li> <li><code>Windows Script Host</code>是一个<code>language-independent</code>的脚本宿主环境，主要用于执行<code>Windows</code>管理任务</li> <li>Windows脚本宿主有两个版本：
<ul><li>一个基于Windows的版本（<a href="https://docs.microsoft.com/zh-cn/windows-server/administration/windows-commands/wscript" target="_blank" rel="noopener noreferrer">WScript.exe<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>）
，它提供用于设置脚本属性的属性表；运行以<code>vbs</code>为后缀的文件</li> <li>一个基于命令提示符的版本（<a href="https://docs.microsoft.com/zh-cn/windows-server/administration/windows-commands/cscript" target="_blank" rel="noopener noreferrer">CScript.exe<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>
直接执行可查看帮助），它提供命令行。用于设置脚本属性的开关。
<ul><li><code>//E:engine</code> 使用执行脚本的引擎有：<code>VBScript</code>和<code>JScript</code></li></ul></li></ul></li></ul> <h2 id="wscript对象"><a href="#wscript对象" class="header-anchor">#</a> WScript对象</h2> <blockquote><p>所有的<code>Wscript</code>对象都存放在<code>WSHOM.ocx</code>文件中</p></blockquote> <ul><li><a href="https://github.com/microsoft/TypeScript/blob/master/lib/lib.scripthost.d.ts" target="_blank" rel="noopener noreferrer">Windows Script Host APIS<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <h3 id="wscript对象的属性"><a href="#wscript对象的属性" class="header-anchor">#</a> WScript对象的属性</h3> <table><thead><tr><th>属性</th> <th>返回值类型</th> <th>说明</th></tr></thead> <tbody><tr><td>Application</td> <td>Object</td> <td>返回 IHost_Class 对象（Wscript 对象）。</td></tr> <tr><td>Arguments</td> <td>IArguments_Class</td> <td>返回 WshArguments 对象（参数集）。</td></tr> <tr><td>BuildVersion</td> <td>Long</td> <td>返回 Windows 脚本宿主的内部版本。</td></tr> <tr><td>FullName</td> <td>String</td> <td>返回宿主可执行文件（CScript.exe 或 WScript.exe）的全路径。</td></tr> <tr><td>Interactive</td> <td>Boolean</td> <td>设置或确定脚本模式。</td></tr> <tr><td>Name</td> <td>String</td> <td>WScript 对象（宿主可执行文件）的名称。</td></tr> <tr><td>Path</td> <td>String</td> <td>返回包含宿主可执行文件（CScript.exe 或 WScript.exe）的路径名称。</td></tr> <tr><td>ScriptFullName</td> <td>String</td> <td>返回当前运行脚本的完整路径。</td></tr> <tr><td>ScriptName</td> <td>String</td> <td>返回当前运行脚本的文件名。</td></tr> <tr><td>StdIn</td> <td>TextStream</td> <td>显示当前脚本的输入流。</td></tr> <tr><td>StdErr</td> <td>TextStream</td> <td>显示当前脚本的错误输出流。<code>Write</code>输出，<code>WriteLine</code>换行输出</td></tr> <tr><td>StdOut</td> <td>TextStream</td> <td>显示当前脚本的输出流。<code>Write</code>输出，<code>WriteLine</code>换行输出</td></tr> <tr><td>Timeout</td> <td>Long</td> <td>超时设定秒：允许脚本运行的最长时间。</td></tr> <tr><td>Version</td> <td>String</td> <td>返回 Windows 脚本宿主的版本。</td></tr></tbody></table> <h3 id="wscript对象的方法"><a href="#wscript对象的方法" class="header-anchor">#</a> WScript对象的方法</h3> <table><thead><tr><th>方法</th> <th>参数</th> <th>返回值</th> <th>说明</th></tr></thead> <tbody><tr><td>ConnectObject</td> <td>(Object As Object, Prefix As String)</td> <td>无</td> <td>将对象的事件源连接到具有给定前缀的函数。</td></tr> <tr><td>CreateObject</td> <td>(ProgID As String, [Prefix As String])</td> <td>Object</td> <td>创建对象。</td></tr> <tr><td>DisconnectObject</td> <td>(Object As Object)</td> <td>无</td> <td>断开已连接对象的事件源的连接。</td></tr> <tr><td>Echo</td> <td>(ParamArray pArgs() As Variant)</td> <td>无</td> <td>将文本输出到消息框中或命令控制台窗口。</td></tr> <tr><td>GetObject</td> <td>(Pathname As String, [ProgID As String], [Prefix As String])</td> <td>Object</td> <td>检索现有的对象或从文件中创建新对象。</td></tr> <tr><td>Quit</td> <td>([ExitCode As Long])</td> <td>无</td> <td>强制脚本停止执行。</td></tr> <tr><td>Sleep</td> <td>(Time As Long)</td> <td>无</td> <td>在指定的时间长度内将脚本执行挂起，然后继续执行。</td></tr></tbody></table> <h2 id="常用组件对象"><a href="#常用组件对象" class="header-anchor">#</a> 常用组件对象</h2> <blockquote><p>所有对象都可通过<code>Power Shell</code>命令查看属性和方法<code>New-Object -ComObject &quot;对象名称&quot; | Get-Member</code>，
获取本机所有<code>COM</code>组件对象脚本 <a href="/files/Get-COM-Objects.bat">Get-COM-Objects.bat</a></p></blockquote> <blockquote><p>都在注册表<code>HKEY_CLASSES_ROOT</code>注册表项中，正常情况下项中带有<code>CLSID</code>键的是脚本可创建的</p></blockquote> <table><thead><tr><th>对象</th> <th>说明</th></tr></thead> <tbody><tr><td>WScript.Shell</td> <td>脚本外壳</td></tr> <tr><td>Wscript.NetWork</td> <td>提供网络连接和远程打印机管理的函数。</td></tr> <tr><td>AspSmartUpload.SmartUpload</td> <td></td></tr> <tr><td>CDO.Configuration</td> <td></td></tr> <tr><td>CDONTS.NewMail</td> <td>邮件发送的组件</td></tr> <tr><td>Huang.UploadFile</td> <td></td></tr> <tr><td>InternetExplorer.application</td> <td></td></tr> <tr><td>JMail.message</td> <td>邮件发送的组件</td></tr> <tr><td>MSWC.AdRotator</td> <td></td></tr> <tr><td>MSWC.BrowserType</td> <td></td></tr> <tr><td>MSWC.NextLink</td> <td></td></tr> <tr><td>Shell.Application</td> <td>Windows外壳</td></tr> <tr><td>SQLOLE.SQLServer</td> <td></td></tr> <tr><td>WSHController</td> <td></td></tr> <tr><td>System.IO.StringWriter</td> <td></td></tr> <tr><td>Registry</td> <td>注册表</td></tr></tbody></table> <table><thead><tr><th>ADODB对象</th> <th>说明</th></tr></thead> <tbody><tr><td>ADODB.Command</td> <td></td></tr> <tr><td>ADODB.Connection</td> <td>提供数据库连接对象</td></tr> <tr><td>ADODB.Error</td> <td></td></tr> <tr><td>ADODB.Parameter</td> <td></td></tr> <tr><td>ADODB.Record</td> <td></td></tr> <tr><td>ADODB.Recordset</td> <td>提供数据库返回结果集对象</td></tr> <tr><td>ADODB.Stream</td> <td></td></tr> <tr><td>ADOMD.Catalog</td> <td></td></tr> <tr><td>ADOMD.Cellset</td> <td></td></tr> <tr><td>ADOX.Catalog</td> <td>包含描述数据源模式目录的集合</td></tr> <tr><td>ADOX.Column</td> <td>表示表、索引或关键字的列</td></tr> <tr><td>ADOX.Group</td> <td>表示在安全数据库内有访问权限的组帐号</td></tr> <tr><td>ADOX.Index</td> <td>表示数据库表中的索引</td></tr> <tr><td>ADOX.Key</td> <td>表示数据库表中的主关键字、外部关键字或唯一关键字</td></tr> <tr><td>ADOX.Procedure</td> <td>表示存储的过程</td></tr> <tr><td>ADOX.Table</td> <td>表示数据库表，包括列、索引和关键字</td></tr> <tr><td>ADOX.User</td> <td>表示在安全数据库内具有访问权限的用户帐号</td></tr> <tr><td>ADOX.View</td> <td>表示记录或虚拟表的过滤集</td></tr></tbody></table> <table><thead><tr><th>office对象</th> <th>说明</th></tr></thead> <tbody><tr><td>Word.Application</td> <td>office</td></tr> <tr><td>Word.Document</td> <td></td></tr> <tr><td>Excel.Application</td> <td>提供EXCEL操作对象</td></tr> <tr><td>Excel.Chart</td> <td></td></tr> <tr><td>Excel.Sheet</td> <td></td></tr> <tr><td>Outlook.Application</td> <td>office</td></tr> <tr><td>PowerPoint.Application</td> <td>office</td></tr> <tr><td>MSGraph.Application</td> <td>office</td></tr></tbody></table> <table><thead><tr><th>WIA对象</th> <th>说明</th></tr></thead> <tbody><tr><td>WIA.ImageFile</td> <td>图像处理组件：加载图片</td></tr> <tr><td>WIA.ImageProcess</td> <td>图像处理组件：转换图片格式</td></tr> <tr><td>WIA.Rational</td> <td></td></tr> <tr><td>WIA.Vector</td> <td></td></tr></tbody></table> <blockquote><p>所有<code>Scripting</code>对象都存放在<code>SCRRUN.DLL</code>文件中</p></blockquote> <table><thead><tr><th>Scripting对象</th> <th>说明</th></tr></thead> <tbody><tr><td>Scripting.Dictionary</td> <td>用来返回存放键值对的字典对象，读取DOS环境变量，读取链接中的设置</td></tr> <tr><td>Scripting.Encoder</td> <td>编码</td></tr> <tr><td>Scripting.FileSystemObject</td> <td>提供一整套文件系统操作函数</td></tr> <tr><td>Scripting.Signer</td> <td>签名</td></tr></tbody></table> <table><thead><tr><th>Collections对象</th> <th>说明</th></tr></thead> <tbody><tr><td>System.Collections.ArrayList</td> <td>包含动态数组的添加元素、删除元素、遍历、统计元素个数、清空</td></tr> <tr><td>System.Collections.Hashtable</td> <td></td></tr> <tr><td>System.Collections.Queue</td> <td>包含队列的添加元素（入队）、删除元素（出队）、遍历、统计元素个数、清空</td></tr> <tr><td>System.Collections.SortedList</td> <td></td></tr> <tr><td>System.Collections.Stack</td> <td>包含堆栈的添加元素（压栈）、删除元素（出栈）、遍历、统计元素个数、清空</td></tr></tbody></table> <h2 id="http"><a href="#http" class="header-anchor">#</a> HTTP</h2> <blockquote><p>微软提供了二套API：<code>WinINet</code>, <code>WinHTTP</code>（分别封装于<code>system32</code>目录下的<code>wininet.dll</code>和<code>winhttp.dll</code>内）
二者主要区别在于后者更为安全和稳定，可以说<code>WinHTTP</code>是<code>WinINet</code>的升级版</p></blockquote> <blockquote><p><code>XMLHttpRequest</code>是基于<code>WinInet</code>封装的，而<code>WinHttpRequest</code>和<code>ServerXMLHTTPRequest</code>则是基于<code>WinHTTP</code>封装的
稳定性属<code>XMLHttpRequest</code>为最差,封装成<code>COM</code>形式主要是为了方便<code>js</code>、<code>vbs</code>等脚本的调用</p></blockquote> <blockquote><p><code>XMLRequest</code>成员参考缺点：和浏览器挂钩，大多情况下会共享<code>cookies</code>、<code>session</code>、不支持单独设置代理。
优点：和浏览器挂钩，大多情况下会共享<code>cookies</code>、<code>session</code></p></blockquote> <blockquote><p><code>ServerXMLHTTP</code>成员参考缺点：系统没有对应<code>dll</code>的情况下程序需要外挂一个<code>dll</code>文件。优点：脱离浏览器，使用代理方便</p></blockquote> <blockquote><p><code>WinHttpRequest</code>成员参考缺点：暂无。优点：脱离浏览器，使用代理方便，
<code>WinHttp.WinHttpRequest.5.1</code>是<code>msxml4.0</code>的底层对象，也就是说<code>XMLHTTP</code>、<code>ServerXMLHTTP</code>也是在它的基础上封装而来</p></blockquote> <ul><li><a href="https://docs.microsoft.com/zh-cn/windows/win32/winhttp/winhttprequest" target="_blank" rel="noopener noreferrer">WinHttpRequest对象<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://docs.microsoft.com/zh-cn/previous-versions/windows/desktop/ms764730%28v%3dvs.85%29" target="_blank" rel="noopener noreferrer">DOM参考<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <h2 id="图像处理"><a href="#图像处理" class="header-anchor">#</a> 图像处理</h2> <blockquote><p><code>WIA</code>全称：<code>WindowsImageAcquisition</code>，自动化层是一个功能齐全的图像处理组件，可提供端到端的图像处理功能。
<code>WIA</code>自动化层可以轻松地从数码相机，扫描仪或网络摄像头获取图像，以及旋转，缩放和注释图像文件。
<code>WIA Automation Layer</code>取代了<code>Windows Image Acquisition（WIA）1.0</code>提供的<code>WIA</code>脚本模型。</p></blockquote> <blockquote><p><code>New-Object -ComObject &quot;WIA.ImageFile&quot; | Get-Member</code></p></blockquote> <blockquote><p><code>New-Object -ComObject &quot;WIA.ImageProcess&quot; | Get-Member</code></p></blockquote> <ul><li><a href="https://docs.microsoft.com/zh-cn/windows/win32/wia/-wia-startpage" target="_blank" rel="noopener noreferrer">Windows图像采集（WIA）<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://docs.microsoft.com/zh-cn/previous-versions/windows/desktop/wiaaut/-wiaaut-howto-use-filters" target="_blank" rel="noopener noreferrer">使用<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://docs.microsoft.com/zh-cn/previous-versions/windows/desktop/wiaaut/-wiaaut-vbscript-constants" target="_blank" rel="noopener noreferrer">常量<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://blog.csdn.net/AMinfo/article/details/8100436" target="_blank" rel="noopener noreferrer">Windows Image Acquisition<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://blog.csdn.net/AMinfo/article/details/8100460" target="_blank" rel="noopener noreferrer">WIA图片处理<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <h2 id="操作文件"><a href="#操作文件" class="header-anchor">#</a> 操作文件</h2> <blockquote><p><code>Scripting.FileSystemObject</code>对象提供的功能：<code>New-Object -ComObject &quot;Scripting.FileSystemObject&quot; | Get-Member</code></p></blockquote> <ul><li><a href="https://docs.microsoft.com/zh-cn/previous-versions/windows/internet-explorer/ie-developer/windows-scripting/d6dw7aeh(v=vs.84)" target="_blank" rel="noopener noreferrer">FileSystemObject简介<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://docs.microsoft.com/zh-cn/office/vba/language/reference/user-interface-help/filesystemobject-object" target="_blank" rel="noopener noreferrer">FileSystemObject 对象<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://blog.csdn.net/pl1612127/article/details/77862174" target="_blank" rel="noopener noreferrer">FileSystemObject操作文件<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <p><strong>对象和集合</strong></p> <table><thead><tr><th>对象/集合</th> <th>描述</th></tr></thead> <tbody><tr><td>Drive</td> <td>包含储存设备的信息，包括硬盘、光驱、ram盘、网络驱动器</td></tr> <tr><td>Drives</td> <td>提供一个物理和逻辑驱动器的列表</td></tr> <tr><td>File</td> <td>检查和处理文件</td></tr> <tr><td>Files</td> <td>提供包含在文件夹内的所有文件的列表</td></tr> <tr><td>Folder</td> <td>检查和处理文件夹</td></tr> <tr><td>Folders</td> <td>提供在 Folder 内的所有文件夹的列表</td></tr> <tr><td>TextStream</td> <td>对象。用来读写文本文件。</td></tr></tbody></table> <blockquote><p>注意:<code>TextStream</code>对文件只可以从上往下读取，指针无法任意定位，也无法往回走。</p></blockquote> <ul><li><code>fso.OpenTextFile(path,[mode,create,encoding])</code> <ul><li><code>mode</code> 模式,缺省为只读方式打开
<ul><li><code>ForReading=1</code> 以只读方式打开</li> <li><code>ForWriting=2</code> 以读写方式打开</li> <li><code>ForAppending=8</code> 以附加方式打开</li></ul></li> <li><code>create</code> 不存在时是否创建缺省为否,即不创建文件</li> <li><code>encoding</code> 何种方式打开,缺省以<code>ASCII</code>方式
<ul><li><code>TristateUseDefault=-2</code> 以系统默认方式打开</li> <li><code>TristateTrue=-1</code> 以<code>Unicode</code>方式打开</li> <li><code>TristateFalse=0</code> 以<code>ASCII</code>方式打开</li></ul></li></ul></li> <li><code>fso.CreateTextFile(path,[overrwite,unicode])</code> <ul><li><code>overrwite</code> 是否覆盖,缺省为是</li> <li><code>unicode</code> 是否以<code>Unicode</code>方式创建,缺省为<code>false</code>,即以<code>ASCII</code>方式创建</li></ul></li></ul> <h2 id="shell"><a href="#shell" class="header-anchor">#</a> Shell</h2> <ul><li>Shell.Application <a href="https://docs.microsoft.com/zh-cn/windows/win32/shell" target="_blank" rel="noopener noreferrer">https://docs.microsoft.com/zh-cn/windows/win32/shell<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> <ul><li><a href="https://docs.microsoft.com/zh-cn/windows/win32/shell/shell" target="_blank" rel="noopener noreferrer">https://docs.microsoft.com/zh-cn/windows/win32/shell/shell<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></li> <li><a href="https://www.jb51.net/article/5683_all.htm" target="_blank" rel="noopener noreferrer">Wscript.Shell 对象详细介绍<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://www.jb51.net/shouce/script56/script56_chs/html/wsobjwshshell.htm" target="_blank" rel="noopener noreferrer">WshShell 对象<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://www.cnblogs.com/bitssea/p/12590701.html" target="_blank" rel="noopener noreferrer">WScript.Shell 与 Shell.Application 的不同<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <ul><li><code>Wscript.Shell</code>对象提供的功能：<code>New-Object -ComObject &quot;Wscript.Shell&quot; | Get-Member</code></li> <li><code>Shell.Application</code>对象提供的功能：<code>New-Object -ComObject &quot;Shell.Application&quot; | Get-Member</code></li></ul> <ul><li><code>Run</code> <code>Exec</code> 执行<code>cmd</code>命令，同<code>Shell.Application</code>的<a href="https://docs.microsoft.com/en-us/windows/win32/shell/shell-shellexecute" target="_blank" rel="noopener noreferrer"><code>ShellExecute</code><span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><code>CreateShortcut</code> 创建快捷方式</li> <li><code>SpecialFolders</code> 访问<code>Windows</code>的<code>shell</code>文件夹</li> <li><code>Environment</code> 操作环境变量</li> <li><code>RegRead</code> 从注册表中返回指定的键或值</li> <li><code>RegWrite</code> 在注册表中设置指定的键或值</li> <li><code>RegDelete</code> 从注册表中删除指定的键或值</li> <li><code>SendKeys</code> 模拟按键</li> <li><code>Popup</code> 显示包含指定消息的消息弹出窗口</li> <li><code>ExpandEnvironmentStrings</code> 返回环境变量的扩展值
<ul><li><code>ExpandEnvironmentStrings(&quot;%USERNAME%&quot;)</code> 获取用户名</li> <li><code>ExpandEnvironmentStrings(&quot;%ComputerName%&quot;)</code> 获取计算机名</li></ul></li></ul> <table><thead><tr><th>变量名</th> <th>说明</th></tr></thead> <tbody><tr><td>NUMBER_OF_PROCESSORS</td> <td>计算机上运行的处理器数目。</td></tr> <tr><td>PROCESSOR_ARCHITECTURE</td> <td>用户工作站使用的处理器类型。</td></tr> <tr><td>PROCESSOR_IDENTIFIER</td> <td>用户工作站的处理器 ID。</td></tr> <tr><td>PROCESSOR_LEVEL</td> <td>用户工作站的处理器级。</td></tr> <tr><td>PROCESSOR_REVISION</td> <td>用户工作站的处理器版本。</td></tr> <tr><td>OS</td> <td>用户工作站所用的操作系统。</td></tr> <tr><td>COMSPEC</td> <td>用于运行“命令提示”窗口的命令（通常为 cmd.exe）。</td></tr> <tr><td>HOMEDRIVE</td> <td>本地主驱动器（通常为 C 驱动器）。</td></tr> <tr><td>HOMEPATH</td> <td>用户的默认路径（在 Windows NT 上通常为 usersdefault）。</td></tr> <tr><td>PATH</td> <td>路径环境变量。</td></tr> <tr><td>PATHEXT</td> <td>可执行文件的扩展名（通常为 .com、 .exe、.bat 或 .cmd）。</td></tr> <tr><td>PROMPT</td> <td>命令提示符（通常为 ＄P＄G）。</td></tr> <tr><td>SYSTEMDRIVE</td> <td>系统所在的本地驱动器（例如，c:）。</td></tr> <tr><td>SYSTEMROOT</td> <td>系统目录（例如，c:winnt）。和 WINDIR 相同。</td></tr> <tr><td>WINDIR</td> <td>系统目录（例如 c:winnt）。和 SYSTEMROOT 相同。</td></tr> <tr><td>TEMP</td> <td>存储临时文件的目录（例如，c:temp）。用户可更改。</td></tr> <tr><td>TMP</td> <td>存储临时文件的目录（例如，c:temp）。用户可更改。</td></tr></tbody></table> <h3 id="执行命令"><a href="#执行命令" class="header-anchor">#</a> 执行命令</h3> <p><strong><code>Run</code></strong></p> <blockquote><p>执行命令完成后返回值是一个整数，就是<code>0</code>成功或<code>1</code>失败两个状态。</p></blockquote> <blockquote><p><code>int Run(string, Variant, Variant)</code>第二个是<code>cmd</code>窗口的风格，第三个是否等待执行完成。</p></blockquote> <table><thead><tr><th>窗口风格</th> <th>说明</th></tr></thead> <tbody><tr><td>0</td> <td>隐藏一个窗口并激活另一个窗口。</td></tr> <tr><td>1</td> <td>如果窗口处于最小化或最大化状态，则系统将其还原到原始大小和位置。第一次显示该窗口时，应用程序应指定此标志。</td></tr> <tr><td>2</td> <td>激活窗口并将其显示为最小化窗口。</td></tr> <tr><td>3</td> <td>激活窗口并将其显示为最大化窗口。</td></tr> <tr><td>4</td> <td>按最近的窗口大小和位置显示窗口。活动窗口保持活动状态。</td></tr> <tr><td>5</td> <td>激活窗口并按当前的大小和位置显示它。</td></tr> <tr><td>6</td> <td>最小化指定的窗口，并按照Z顺序激活下一个顶部窗口。</td></tr> <tr><td>7</td> <td>将窗口显示为最小化窗口。活动窗口保持活动状态。</td></tr> <tr><td>8</td> <td>将窗口显示为当前状态。活动窗口保持活动状态。</td></tr> <tr><td>9</td> <td>如果窗口处于最小化或最大化状态，则系统将其还原到原始大小和位置。还原最小化窗口时，应用程序应指定此标志。</td></tr> <tr><td>10</td> <td>根据启动应用程序的程序状态来设置显示状态</td></tr></tbody></table> <p><strong><code>Exec</code></strong></p> <blockquote><p>返回值是一个对象，从返回对象中可以获得控制台输出信息和控制台错误信息，即<code>StdOut</code> 和 <code>StdErr</code> 属性等。</p></blockquote> <ul><li><code>Exec</code>类具有属性<code>ExitCode</code>、<code>ProcessID</code>、<code>Status</code>、<code>StdErr</code>、<code>StdIn</code>、<code>StdOut</code>以及一个函数<code>Terminate</code> <ul><li><code>Status</code>属性具有三个值：0为正在执行，1为完成，2为失败</li> <li>获取输出信息：<code>StdOut.ReadAll()</code></li></ul></li></ul> <p><strong>Shell.Application运行文件的5种方法</strong></p> <div class="language-vb extra-class"><pre class="language-vb"><code><span class="token keyword">Set</span> objShellApp <span class="token operator">=</span> CreateObject<span class="token punctuation">(</span><span class="token string">&quot;Shell.Application&quot;</span><span class="token punctuation">)</span>
<span class="token keyword">Set</span> objFolder <span class="token operator">=</span> objShellApp<span class="token punctuation">.</span><span class="token keyword">NameSpace</span><span class="token punctuation">(</span><span class="token string">&quot;c:/&quot;</span><span class="token punctuation">)</span>
<span class="token comment">' 方法1</span>
objFolder<span class="token punctuation">.</span>Items<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>item<span class="token punctuation">(</span><span class="token string">&quot;demo.exe&quot;</span><span class="token punctuation">)</span><span class="token punctuation">.</span>invokeverb
<span class="token comment">' 方法2</span>
objFolder<span class="token punctuation">.</span>Items<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>item<span class="token punctuation">(</span><span class="token string">&quot;demo.exe&quot;</span><span class="token punctuation">)</span><span class="token punctuation">.</span>InvokeVerbEx
<span class="token comment">' 方法3</span>
objShellApp<span class="token punctuation">.</span>Open<span class="token punctuation">(</span><span class="token string">&quot;C:/demo.exe&quot;</span><span class="token punctuation">)</span>
<span class="token comment">' 方法4,可以加参数和设置参数值</span>
objShellApp<span class="token punctuation">.</span>ShellExecute <span class="token string">&quot;demo.exe&quot;</span><span class="token punctuation">,</span><span class="token string">&quot;&quot;</span><span class="token punctuation">,</span><span class="token string">&quot;c:/&quot;</span><span class="token punctuation">,</span><span class="token string">&quot;&quot;</span><span class="token punctuation">,</span> <span class="token number">0</span>
<span class="token comment">' 方法5：在文件上打开鼠标邮件点击打开按钮</span>
<span class="token keyword">Set</span> objFolderItem <span class="token operator">=</span> objShellApp<span class="token punctuation">.</span><span class="token keyword">NameSpace</span><span class="token punctuation">(</span><span class="token string">&quot;C:/&quot;</span><span class="token punctuation">)</span><span class="token punctuation">.</span>Items<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>item<span class="token punctuation">(</span><span class="token string">&quot;demo.exe&quot;</span><span class="token punctuation">)</span>
<span class="token keyword">Set</span> objFIVs <span class="token operator">=</span> objFolderItem<span class="token punctuation">.</span>Verbs<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">For</span> i<span class="token operator">=</span><span class="token number">0</span> <span class="token keyword">To</span> objFIVs<span class="token punctuation">.</span>Count <span class="token operator">-</span> <span class="token number">1</span>
    <span class="token comment">' MsgBox objFIVs.Item(i)</span>
    <span class="token keyword">Set</span> objFIV <span class="token operator">=</span> objFIVs<span class="token punctuation">.</span>Item<span class="token punctuation">(</span>i<span class="token punctuation">)</span>
    <span class="token keyword">If</span> objFIV<span class="token punctuation">.</span>Name <span class="token operator">=</span> <span class="token string">&quot;打开(&amp;O)&quot;</span> <span class="token keyword">Then</span> <span class="token comment">'右键菜单中在中文系统是&quot;打开(&amp;O)&quot;，英文自己改</span>
        objFIV<span class="token punctuation">.</span>DoIt
        <span class="token keyword">Exit</span> <span class="token keyword">For</span>
    <span class="token keyword">End</span> <span class="token keyword">IF</span>
<span class="token keyword">Next</span>
</code></pre></div><h3 id="特殊文件夹"><a href="#特殊文件夹" class="header-anchor">#</a> 特殊文件夹</h3> <blockquote><p><code>SpecialFolders</code>属性提供<code>WshSpecialFolders</code>对象以便访问<code>Windows</code>的<code>shell</code>文件夹</p></blockquote> <blockquote><p>使用：<code>WshShell.SpecialFolders(&quot;strFolderName&quot;)</code>，如果没有查询的目录则返回<code>NULL</code></p></blockquote> <table><thead><tr><th>变量名</th> <th>说明</th></tr></thead> <tbody><tr><td>AllUsersDesktop</td> <td>公共桌面</td></tr> <tr><td>AllUsersStartMenu</td> <td>公共程式</td></tr> <tr><td>AllUsersPrograms</td> <td>公共程序</td></tr> <tr><td>AllUsersStartup</td> <td>公共启动</td></tr> <tr><td>Desktop</td> <td>桌面</td></tr> <tr><td>Favorites</td> <td>收藏</td></tr> <tr><td>Fonts</td> <td>字体</td></tr> <tr><td>MyDocuments</td> <td>我的文档</td></tr> <tr><td>NetHood</td> <td>网络</td></tr> <tr><td>PrintHood</td> <td>打印机</td></tr> <tr><td>Programs</td> <td>程序</td></tr> <tr><td>Recent</td> <td>最近</td></tr> <tr><td>SendTo</td> <td>发给</td></tr> <tr><td>StartMenu</td> <td>开始菜单</td></tr> <tr><td>Startup</td> <td>启动</td></tr> <tr><td>Templates</td> <td>模板</td></tr> <tr><td>AppData</td> <td>应用程序数据</td></tr></tbody></table> <h3 id="模拟按键"><a href="#模拟按键" class="header-anchor">#</a> 模拟按键</h3> <ul><li><a href="https://docs.microsoft.com/zh-cn/windows/win32/inputdev/user-input" target="_blank" rel="noopener noreferrer">https://docs.microsoft.com/zh-cn/windows/win32/inputdev/user-input<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <ul><li><code>SendKeys</code>键击参数说明
<ul><li><code>Enter</code>回车建表示<code>{Enter}</code>、字母<code>A</code>表示<code>{A}</code>、数字<code>2</code>表示<code>{2}</code>等
<ul><li>示例<code>Wshshell.SendKeys(&quot;{Enter}&quot;)</code>、<code>Wshshell.SendKeys(&quot;{A}&quot;)</code>、<code>Wshshell.SendKeys(&quot;{2}&quot;)</code></li></ul></li> <li>组合键<code>Shift</code>用<code>+</code>代替、<code>Ctrl</code>用<code>^</code>代替、<code>Alt</code>用<code>%</code>代替
<ul><li>示例<code>Wshshell.SendKeys(&quot;+%{DELETE}&quot;)</code>、<code>Wshshell.SendKeys(&quot;^{C}&quot;)</code>、<code>Wshshell.SendKeys(&quot;^{V}&quot;)</code></li></ul></li> <li>模拟快捷键<code>Ctrl + S</code>保存内容：<code>Wshshell.SendKeys(&quot;^{s}&quot;)</code></li> <li>使用<code>+{f10}</code>可以z有限制地方调用，如调用桌面菜单<code>{f5}+{f10}</code></li></ul></li></ul> <h2 id="wmi和mi"><a href="#wmi和mi" class="header-anchor">#</a> WMI和MI</h2> <blockquote><p>Windows Management Instrumentation（WMI）的新版本是 Windows Management Infrastructure (MI)</p></blockquote> <blockquote><p><code>SWBEM</code>脚本是可以用来访问和控制WMI内部对象的一系列可用在脚本中的对象，
脚本通过访问<code>wbemdisp.dll</code>这个<code>library</code>来访问<code>VMI</code>对象，这个仅被设计用来为脚本工作。</p></blockquote> <blockquote><p>查询方式类似sql语句（其实系统信息也是存储在计算中一个类似数据库的文件中）获取我们需要的对象的记录集</p></blockquote> <ul><li><a href="https://docs.microsoft.com/zh-cn/windows/win32/wmisdk/wmi-reference" target="_blank" rel="noopener noreferrer">WMI参考<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://docs.microsoft.com/zh-cn/windows/win32/wmisdk/wmi-start-page" target="_blank" rel="noopener noreferrer">Windows Management Instrumentation（WMI）<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <ul><li><a href="https://docs.microsoft.com/zh-cn/previous-versions/windows/desktop/wmi_v2/why-use-mi-" target="_blank" rel="noopener noreferrer">为什么要使用Windows Management Infrastructure (MI)<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <ul><li><a href="https://docs.microsoft.com/zh-cn/windows/win32/wmisdk/scripting-api-objects" target="_blank" rel="noopener noreferrer">WbemScripting脚本API对象<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://docs.microsoft.com/en-us/previous-versions/windows/desktop/regprov/system-registry-provider" target="_blank" rel="noopener noreferrer">系统注册表提供者<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://docs.microsoft.com/zh-cn/windows/win32/cimwin32prov/win32-provider" target="_blank" rel="noopener noreferrer">Win32 Provider-可以看到表对应的字段有哪些<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <table><thead><tr><th>表名</th> <th>说明</th></tr></thead> <tbody><tr><td>Win32_BaseBoard</td> <td>主板</td></tr> <tr><td>Win32_BIOS</td> <td>BIOS芯片</td></tr> <tr><td>Win32_BootConfiguration</td> <td>系统启动配置</td></tr> <tr><td>Win32_CDROMDrive</td> <td>光盘驱动器</td></tr> <tr><td>Win32_ComputerSystem</td> <td>操作系统信息，系统位数</td></tr> <tr><td>Win32_DesktopMonitor</td> <td>显示器</td></tr> <tr><td>Win32_DiskDrive</td> <td>硬盘驱动器</td></tr> <tr><td>Win32_DiskPartition</td> <td>磁盘分区</td></tr> <tr><td>Win32_Group</td> <td>系统管理组</td></tr> <tr><td>Win32_GroupUser</td> <td>系统组帐号</td></tr> <tr><td>Win32_Keyboard</td> <td>键盘</td></tr> <tr><td>Win32_LogicalDisk</td> <td>逻辑磁盘</td></tr> <tr><td>Win32_LogicalMemoryConfiguration</td> <td>逻辑内存配置</td></tr> <tr><td>Win32_NetworkAdapter</td> <td>网络适配器</td></tr> <tr><td>Win32_NetworkAdapterConfiguration</td> <td>网络适配器设置</td></tr> <tr><td>Win32_NetworkClient</td> <td>已安装的网络客户端</td></tr> <tr><td>Win32_NetworkProtocol</td> <td>已安装的网络协议</td></tr> <tr><td>Win32_OperatingSystem</td> <td>操作系统信息，系统版本</td></tr> <tr><td>Win32_PageFile</td> <td>系统页文件信息</td></tr> <tr><td>Win32_PageFileSetting</td> <td>页文件设置</td></tr> <tr><td>Win32_ParallelPort</td> <td>并口</td></tr> <tr><td>Win32_PhysicalMemory</td> <td>物理内存</td></tr> <tr><td>Win32_PointingDevice</td> <td>点输入设备，如鼠标</td></tr> <tr><td>Win32_POTSModem</td> <td>MODEM</td></tr> <tr><td>Win32_POTSModemToSerialPort</td> <td>MODEM端口</td></tr> <tr><td>Win32_Printer</td> <td>打印机</td></tr> <tr><td>Win32_PrinterConfiguration</td> <td>打印机设置</td></tr> <tr><td>Win32_PrintJob</td> <td>打印机任务</td></tr> <tr><td>Win32_Process</td> <td>系统进程</td></tr> <tr><td>Win32_Processor</td> <td>CPU处理器</td></tr> <tr><td>Win32_SerialPort</td> <td>串口</td></tr> <tr><td>Win32_Service</td> <td>系统安装的服务</td></tr> <tr><td>Win32_Share</td> <td>共享</td></tr> <tr><td>Win32_SoundDevice</td> <td>多媒体设置</td></tr> <tr><td>Win32_StartupCommand</td> <td>系统自动启动程序</td></tr> <tr><td>Win32_SystemDriver</td> <td>驱动程序</td></tr> <tr><td>Win32_TCPIPPrinterPort</td> <td>打印机端口</td></tr> <tr><td>Win32_Thread</td> <td>系统线程</td></tr> <tr><td>Win32_TimeZone</td> <td>时区</td></tr> <tr><td>Win32_USBController</td> <td>USB控制器</td></tr> <tr><td>Win32_UserAccount</td> <td>用户帐号</td></tr> <tr><td>Win32_VideoController</td> <td>显卡细节。</td></tr> <tr><td>Win32_VideoSettings</td> <td>显卡支持的显示模式。</td></tr> <tr><td>Win32_ScheduledJob</td> <td>创建一个作业AT命令（不是任务计划）</td></tr> <tr><td>Win32_NetworkLoginProfile</td> <td>一个特定的用户运行Windows的计算机系统上的网络登录信息。</td></tr> <tr><td>MSFT_NetAdapter</td> <td>逻辑网络适配器</td></tr> <tr><td>Win32_NetworkConnection</td> <td>一个基于Windows的环境中活动的网络连接</td></tr></tbody></table> <p><strong>创建SWbemServices对象方式</strong></p> <ul><li><a href="https://docs.microsoft.com/zh-cn/windows/win32/wmisdk/swbemservices" target="_blank" rel="noopener noreferrer">SWbemServices object<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <div class="language-vb extra-class"><pre class="language-vb"><code><span class="token keyword">Set</span> objLocator <span class="token operator">=</span> CreateObject<span class="token punctuation">(</span><span class="token string">&quot;WbemScripting.SWbemLocator&quot;</span><span class="token punctuation">)</span>
<span class="token keyword">Set</span> objService <span class="token operator">=</span> objLocator<span class="token punctuation">.</span>ConnectServer<span class="token punctuation">(</span><span class="token string">&quot;.&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;root\cimv2&quot;</span><span class="token punctuation">)</span>

<span class="token comment">' 隐式使用本地计算机(.) 和默认名称空间(&quot;root\cimv2&quot;)</span>
<span class="token keyword">Set</span> objWMIService <span class="token operator">=</span> GetObject<span class="token punctuation">(</span><span class="token string">&quot;winmgmts:&quot;</span><span class="token punctuation">)</span>

<span class="token keyword">Set</span> objinst <span class="token operator">=</span> GetObject<span class="token punctuation">(</span><span class="token string">&quot;WinMgmts:Win32_LogicalDisk&quot;</span><span class="token punctuation">)</span>

<span class="token keyword">Set</span> objWMIService <span class="token operator">=</span> GetObject<span class="token punctuation">(</span><span class="token string">&quot;winmgmts:root\cimv2&quot;</span><span class="token punctuation">)</span>

<span class="token keyword">Set</span> objWMIService <span class="token operator">=</span> GetObject<span class="token punctuation">(</span><span class="token string">&quot;winmgmts://./root/cimv2&quot;</span><span class="token punctuation">)</span>

<span class="token keyword">Set</span> objWMIService <span class="token operator">=</span> GetObject<span class="token punctuation">(</span><span class="token string">&quot;winmgmts:\\.\root\cimv2&quot;</span><span class="token punctuation">)</span>

<span class="token keyword">Set</span> objWMIService <span class="token operator">=</span> GetObject<span class="token punctuation">(</span><span class="token string">&quot;winmgmts:{impersonationlevel=impersonate}!\\.\root\cimv2&quot;</span><span class="token punctuation">)</span>

<span class="token comment">' wmi与cimv2不同</span>
<span class="token keyword">Set</span> objWMIService <span class="token operator">=</span> GetObject<span class="token punctuation">(</span><span class="token string">&quot;winmgmts:\\.\root\wmi&quot;</span><span class="token punctuation">)</span>
</code></pre></div><div class="language-js extra-class"><pre class="language-js"><code><span class="token comment">// JScript.</span>
<span class="token keyword">var</span> LoginProfiles <span class="token operator">=</span> <span class="token function">GetObject</span><span class="token punctuation">(</span><span class="token string">&quot;winmgmts:&quot;</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">InstancesOf</span> <span class="token punctuation">(</span><span class="token string">&quot;Win32_NetworkLoginProfile&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">for</span><span class="token punctuation">(</span>e <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Enumerator</span><span class="token punctuation">(</span>LoginProfiles<span class="token punctuation">)</span> <span class="token punctuation">;</span> <span class="token operator">!</span>e<span class="token punctuation">.</span><span class="token function">atEnd</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">;</span> e<span class="token punctuation">.</span><span class="token function">moveNext</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
   <span class="token keyword">var</span> Profile <span class="token operator">=</span> e<span class="token punctuation">.</span><span class="token function">item</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
   WScript<span class="token punctuation">.</span><span class="token function">Echo</span><span class="token punctuation">(</span>Profile<span class="token punctuation">.</span>Name<span class="token punctuation">)</span><span class="token punctuation">;</span>
   WScript<span class="token punctuation">.</span><span class="token function">Echo</span><span class="token punctuation">(</span>Profile<span class="token punctuation">.</span>LastLogon<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre></div></div> <footer class="page-edit"><div class="edit-link"><a href="https://github.com/woytu/notes-vuepress/edit/master//Shell/WindowsScript.md" target="_blank" rel="noopener noreferrer">在 GitHub 上编辑此页</a> <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></div> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">2020-08-29 22:21:17</span></div></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/Shell/WindowsJScript.html" class="prev">
        WindowsJScript
      </a></span> <span class="next"><a href="/Shell/WindowsVBScript.html">
        WindowsVBScript
      </a>
      →
    </span></p></div> </main></div><div class="global-ui"><!----></div></div>
    <script src="/assets/js/app.269009d6.js" defer></script><script src="/assets/js/3.974b9720.js" defer></script><script src="/assets/js/63.a9516572.js" defer></script>
  </body>
</html>
